package org.hot100_1;

import java.util.HashSet;
import java.util.Set;

public class leetcode3 {
    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<>();

        for (int num:nums) {
            set.add(num);
        }

        int res = 0;

        for (int i = 0; i < nums.length; i++) {
            int curr = nums[i];
            if (!set.contains(curr - 1)){
                int max = 0;
                while (set.contains(curr)){
                    curr++;
                    max++;
                }
                res = Math.max(res,max);
            }
        }

        return res;
    }
}
